//
//  PickCommentView.m
//  Shengzhuli
//
//  Created by subook on 2017/8/20.
//  Copyright © 2017年 kamangkeji. All rights reserved.
//

#import "PickCommentView.h"
#import "TimeChangeTool.h"

@implementation PickCommentView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        _imageViewsArr = [NSMutableArray array];
        
        [self configUI];
    }
    return self;
}
- (void)setPickViewWithModel:(PickUpModel *)model {
    
    self.headImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.portraitUrl]]];
    self.nickNameLabel.text = model.nickName;
    self.themeLabel.text = model.ruleTitle;
    self.timeAgoLabel.text = [TimeChangeTool updateTimeForRow:model.createDate];
    self.contentLabel.text = model.ruleContent;
    self.zanNumLabel.text = [NSString stringWithFormat:@"%@",model.praise];
    self.pingNumLabel.text = [NSString stringWithFormat:@"%@",model.commentsNumber];

}
- (void)configUI {
    
    _headImageView = [[UIImageView alloc] init];
    //_headImageView.image = GetImage(@"pangza");
    _headImageView.frame = CGRectMake(10, 10, 35, 35);
    [self addSubview:_headImageView];
    
    _nickNameLabel = [[UILabel alloc] init];
    _nickNameLabel.textColor = [UIColor blueColor];
    _nickNameLabel.frame = CGRectMake(50, 10, ScreenW-50-10, 20);
    _nickNameLabel.text = @"玩转地球";
    [self addSubview:_nickNameLabel];
    
    _timeAgoLabel = [[UILabel alloc] init];
    _timeAgoLabel.frame = CGRectMake(50, 30, ScreenW-50-10, 15);
    _timeAgoLabel.textColor = [UIColor grayColor];
    _timeAgoLabel.text = [@"25" stringByAppendingString:@"分钟前发布"];
    _timeAgoLabel.font = [UIFont systemFontOfSize:12];
    [self addSubview:_timeAgoLabel];
    
    _themeLabel = [[UILabel alloc] init];
    _themeLabel.frame = CGRectMake(10, 55, ScreenW-20, 30);
    _themeLabel.text = @"";
    [self addSubview:_themeLabel];
    
    _contentLabel = [[UILabel alloc] init];
    _contentLabel.frame = CGRectMake(10, _themeLabel.frame.origin.y+_themeLabel.frame.size.height+10, ScreenW-20, 60);
    _contentLabel.textColor = [UIColor grayColor];
    _contentLabel.font = [UIFont systemFontOfSize:14];
    _contentLabel.numberOfLines = 0;
    _contentLabel.text = @"";
    [self addSubview:_contentLabel];
    
    //三张图片
    CGFloat imageWidth = (ScreenW-20-5*2)/3;
    CGFloat space = (ScreenW-3*imageWidth-20)/2;
    for (int i=0; i<3; i++) {
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:(CGRectMake(10+i*(imageWidth+space), _contentLabel.frame.origin.y+_contentLabel.size.height+10, imageWidth, imageWidth))];
        [_imageViewsArr addObject:imgView];
        //imgView.image = GetImage(@"pangza");
        imgView.tag = 1000+i;
        [self addSubview:imgView];
    };
    
    _bottomview = [[UIView alloc] initWithFrame:(CGRectMake(ScreenW-90, _contentLabel.frame.origin.y+60+imageWidth+20, 80, 20))];
    [self addSubview:_bottomview];
    _zanButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    ;
    _zanButton.frame = CGRectMake(0, 0, 20, 20);
    [_zanButton setImage:GetImage(@"点赞") forState:(UIControlStateNormal)];
    [_zanButton setImage:GetImage(@"点赞selected") forState:(UIControlStateSelected)];
    [_zanButton addTarget:self action:@selector(zanButtonclick) forControlEvents:(UIControlEventTouchUpInside)];
    [_bottomview addSubview:_zanButton];
    
    _zanNumLabel = [[UILabel alloc] initWithFrame:(CGRectMake(20, 0, 20, 20))];
    _zanNumLabel.font = [UIFont systemFontOfSize:12];
    _zanNumLabel.text = @"12";
    _zanNumLabel.textColor = [UIColor grayColor];
    [_bottomview addSubview:_zanNumLabel];
    
    //评论
    _commentButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    _commentButton.frame = CGRectMake(40, 0, 20, 20);
    [_commentButton setImage:GetImage(@"评论") forState:(UIControlStateNormal)];
    [_commentButton addTarget:self action:@selector(pingBUttonClick) forControlEvents:(UIControlEventTouchUpInside)];
    [_bottomview addSubview:_commentButton];
    
    _pingNumLabel = [[UILabel alloc] initWithFrame:(CGRectMake(60, 0, 30, 20))];
    _pingNumLabel.text = @"22";
    _pingNumLabel.textColor = [UIColor grayColor];
    _pingNumLabel.font = [UIFont systemFontOfSize:12];
    [_bottomview addSubview:_pingNumLabel];
    
}
- (void)zanButtonclick {
    
    if (self.zanButtonBlock) {
        self.zanButtonBlock();
    }
}
- (void)pingBUttonClick {
    NSLog(@"点击评论");
    if (self.pingButtonBlock) {
        self.pingButtonBlock();
    }
}


@end
